#!/usr/bin/env python
# -*- coding: utf-8 -*-

import tornado
import tornado.web
from utils import log
import json
from config import etc
from controls import data_img_base_mysql
from utils.session_mc import BaseHandler

user_img_dict = { 1000 : 100000022 }

class UserFullHandler( BaseHandler ) :

    def get( self, userid, img_idx) :
        imgid = user_img_dict[ int(userid) ]
        if not imgid :
            self.write( 'error' )
            return
        res = data_img_base_mysql.get_img_base_by_imgid( imgid )
        log.i( res )
        url = 'http://static.shitouren.com/group'+str(res['group'])+'/'+res['path']+'.'+res['ext']
        log.i( url )
        return self.redirect( url, permanent=True )


class ApiNotFoundHandler( BaseHandler ) :

    def get( self ) :
        raise tornado.web.HTTPError( 503 )

    @tornado.web.asynchronous
    def post( self ) :
        log.i( '503' )
        res = { 'idx':-1, 'ret':-5, 'msg':etc.err_no_api, 'res':{} }
        self.write( json.dumps(res) )
        self.finish()


